home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / ctangle.c < prev    next >
C/C++ Source or Header  |  1994-07-02  |  36KB  |  1,779 lines

  1. /*1:*/
  2. #line 61 "ctangle.w"
  3.  
  4. /*2:*/
  5. #line 177 "ctangle.ch"
  6.  
  7. #include <string.h>
  8. #line 80 "ctangle.w"
  9.  
  10. /*:2*//*6:*/
  11. #line 203 "ctangle.ch"
  12.  
  13. #include <stdio.h>
  14.  
  15. #ifdef __TURBOC__
  16. #include <io.h>
  17. #endif
  18.  
  19. #ifndef _AMIGA 
  20. typedef long int LONG;
  21. typedef char*STRPTR;
  22. #define EXEC_TYPES_H 1 
  23. #endif
  24.  
  25. #ifdef STRINGARRAY
  26. #undef STRINGARRAY 
  27. #endif
  28. #define get_string(n) AppStrings[n].as_Str
  29.  
  30. #include "cweb.h"
  31.  
  32. struct AppString
  33. {
  34. LONG as_ID;
  35. STRPTR as_Str;
  36. };
  37.  
  38. extern struct AppString AppStrings[];
  39.  
  40. /*:6*//*62:*/
  41. #line 873 "ctangle.w"
  42.  
  43. #include <ctype.h> 
  44. #include <stdlib.h> 
  45.  
  46. /*:62*/
  47. #line 62 "ctangle.w"
  48.  
  49. #define banner get_string(MSG_BANNER_CT1)  \
  50.  
  51. #define max_bytes 90000 \
  52.  
  53. #define max_toks 270000
  54. #define max_names 4000 \
  55.  
  56. #define max_texts 2500
  57. #define hash_size 353
  58. #define longest_name 1000
  59. #define stack_size 50
  60. #define buf_size 100 \
  61.  
  62. #define ctangle 0
  63. #define cweave 1 \
  64.  
  65. #define alloc_object(object,size,type)  \
  66. if(!(object= (type*) calloc(size,sizeof(type) ) ) )  \
  67. fatal("",get_string(MSG_FATAL_CO85) ) ; \
  68.  
  69. #define and_and 04
  70. #define lt_lt 020
  71. #define gt_gt 021
  72. #define plus_plus 013
  73. #define minus_minus 01
  74. #define minus_gt 031
  75. #define not_eq 032
  76. #define lt_eq 034
  77. #define gt_eq 035
  78. #define eq_eq 036
  79. #define or_or 037
  80. #define dot_dot_dot 016
  81. #define colon_colon 06
  82. #define period_ast 026
  83. #define minus_gt_ast 027 \
  84.  
  85. #define xisalpha(c) (isalpha(c) &&((eight_bits) c<0200) ) 
  86. #define xisdigit(c) (isdigit(c) &&((eight_bits) c<0200) ) 
  87. #define xisspace(c) (isspace(c) &&((eight_bits) c<0200) ) 
  88. #define xislower(c) (islower(c) &&((eight_bits) c<0200) ) 
  89. #define xisupper(c) (isupper(c) &&((eight_bits) c<0200) ) 
  90. #define xisxdigit(c) (isxdigit(c) &&((eight_bits) c<0200) )  \
  91.  
  92. #define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start) 
  93. #define print_id(c) term_write((c) ->byte_start,length((c) ) ) 
  94. #define llink link
  95. #define rlink dummy.Rlink
  96. #define root name_dir->rlink \
  97.  
  98. #define chunk_marker 0 \
  99.  
  100. #define spotless 0
  101. #define harmless_message 1
  102. #define error_message 2
  103. #define fatal_message 3
  104. #define mark_harmless {if(history==spotless) history= harmless_message;}
  105. #define mark_error history= error_message
  106. #define confusion(s) fatal(get_string(MSG_FATAL_CO66) ,s)  \
  107.  
  108. #define max_file_name_length 256
  109. #define cur_file file[include_depth]
  110. #define cur_file_name file_name[include_depth]
  111. #define web_file_name file_name[0]
  112. #define cur_line line[include_depth] \
  113.  
  114. #define show_banner flags['b']
  115. #define show_happiness flags['h']
  116. #define show_progress flags['p']
  117. #define use_amiga_keywords flags['a']
  118. #define use_german_macros flags['g']
  119. #define indent_param_decl flags['i']
  120. #define order_decl_stmt flags['o']
  121. #define send_error_messages flags['m'] \
  122.  
  123. #define update_terminal fflush(stdout) 
  124. #define new_line putchar('\n') 
  125. #define putxchar putchar
  126. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  127. #define C_printf(c,a) fprintf(C_file,c,a) 
  128. #define C_putc(c) putc(c,C_file)  \
  129.  
  130. #define equiv equiv_or_xref \
  131.  
  132. #define section_flag max_texts \
  133.  
  134. #define string 02
  135. #define join 0177
  136. #define output_defs_flag (2*024000-1)  \
  137.  
  138. #define cur_end cur_state.end_field
  139. #define cur_byte cur_state.byte_field
  140. #define cur_name cur_state.name_field
  141. #define cur_repl cur_state.repl_field
  142. #define cur_section cur_state.section_field \
  143.  
  144. #define section_number 0201
  145. #define identifier 0202 \
  146.  
  147. #define normal 0
  148. #define num_or_id 1
  149. #define unbreakable 3
  150. #define verbatim 4 \
  151.  
  152. #define max_files 256
  153. #define translit_length 10 \
  154.  
  155. #define ignore 0
  156. #define ord 0302
  157. #define control_text 0303
  158. #define translit_code 0304
  159. #define output_defs_code 0305
  160. #define format_code 0306
  161. #define definition 0307
  162. #define begin_C 0310
  163. #define section_name 0311
  164. #define new_section 0312 \
  165.  
  166. #define constant 03 \
  167.  
  168. #define isxalpha(c) ((c) =='_') 
  169. #define ishigh(c) ((unsigned char) (c) >0177)  \
  170.  \
  171.  
  172. #define compress(c) if(loc++<=limit) return(c)  \
  173.  
  174. #define macro 0 \
  175.  
  176. #define app_repl(c)  \
  177. {if(tok_ptr==tok_mem_end)  \
  178. overflow(get_string(MSG_OVERFLOW_CT26) ) ; \
  179. *tok_ptr++= c;} \
  180.  
  181.  
  182. #line 63 "ctangle.w"
  183.  
  184. /*5:*/
  185. #line 203 "ctangle.ch"
  186.  
  187. typedef short boolean;
  188. typedef char unsigned eight_bits;
  189. extern boolean program;
  190. extern int phase;
  191.  
  192. #ifdef __TURBOC__
  193. #define HUGE huge
  194. #else
  195. #define HUGE
  196. #endif
  197.  
  198.  
  199. /*:5*//*7:*/
  200. #line 203 "ctangle.ch"
  201.  
  202. char*section_text;
  203. char*section_text_end;
  204. char*id_first;
  205. char*id_loc;
  206.  
  207. /*:7*//*8:*/
  208. #line 203 "ctangle.ch"
  209.  
  210. extern char*buffer;
  211. extern char*buffer_end;
  212. extern char*loc;
  213. extern char*limit;
  214.  
  215. /*:8*//*9:*/
  216. #line 203 "ctangle.ch"
  217.  
  218. typedef struct name_info{
  219. char HUGE*byte_start;
  220. struct name_info HUGE*link;
  221. union{
  222. struct name_info HUGE*Rlink;
  223.  
  224. char Ilk;
  225. }dummy;
  226. void HUGE*equiv_or_xref;
  227. }name_info;
  228. typedef name_info HUGE*name_pointer;
  229. typedef name_pointer*hash_pointer;
  230. extern char HUGE*byte_mem;
  231. extern name_info HUGE*name_dir;
  232. extern char HUGE*byte_mem_end;
  233. extern name_pointer name_dir_end;
  234. extern name_pointer name_ptr;
  235. extern char HUGE*byte_ptr;
  236. #ifdef __TURBOC__
  237. void far*allocsafe(unsigned long nunits,unsigned long unitsz);
  238. #endif
  239.  
  240. extern name_pointer*hash;
  241. extern hash_pointer hash_end;
  242. extern hash_pointer h;
  243. extern int names_match(name_pointer,char*,int,eight_bits);
  244. extern name_pointer id_lookup(char*,char*,char);
  245.  
  246. extern name_pointer prefix_lookup(char*,char*);
  247. extern name_pointer section_lookup(char*,char*,int);
  248. extern void init_node(name_pointer);
  249. extern void init_p(name_pointer,eight_bits);
  250. extern void print_prefix_name(name_pointer);
  251. extern void print_section_name(name_pointer);
  252. extern void sprint_section_name(char*,name_pointer);
  253.  
  254. /*:9*//*10:*/
  255. #line 203 "ctangle.ch"
  256.  
  257. extern history;
  258. extern int wrap_up(void);
  259. extern void err_print(char*);
  260. extern void fatal(char*,char*);
  261. extern void overflow(char*);
  262.  
  263. /*:10*//*11:*/
  264. #line 203 "ctangle.ch"
  265.  
  266. extern include_depth;
  267. extern FILE**file;
  268. extern FILE*change_file;
  269. extern char*C_file_name;
  270. extern char*tex_file_name;
  271. extern char*idx_file_name;
  272. extern char*scn_file_name;
  273. extern char**file_name;
  274. extern char*change_file_name;
  275. extern int*line;
  276. extern change_line;
  277. extern boolean input_has_ended;
  278. extern boolean changing;
  279. extern boolean web_file_open;
  280. extern boolean get_line(void);
  281. extern void check_complete(void);
  282. extern void reset_input(void);
  283.  
  284. /*:11*//*12:*/
  285. #line 203 "ctangle.ch"
  286.  
  287. typedef unsigned short sixteen_bits;
  288. extern sixteen_bits section_count;
  289. extern boolean*changed_section;
  290. extern boolean change_pending;
  291. extern boolean print_where;
  292.  
  293. /*:12*//*13:*/
  294. #line 203 "ctangle.ch"
  295.  
  296. extern int argc;
  297. extern char**argv;
  298. extern boolean flags[];
  299.  
  300. /*:13*//*14:*/
  301. #line 203 "ctangle.ch"
  302.  
  303. extern FILE*C_file;
  304. extern FILE*tex_file;
  305. extern FILE*idx_file;
  306. extern FILE*scn_file;
  307. extern FILE*active_file;
  308.  
  309. /*:14*//*15:*/
  310. #line 203 "ctangle.ch"
  311.  
  312. extern void common_init(void);
  313. extern void print_stats(void);
  314. #line 204 "ctangle.ch"
  315.  
  316. #line 125 "ctangle.w"
  317.  
  318. /*:15*/
  319. #line 64 "ctangle.w"
  320.  
  321. /*16:*/
  322. #line 149 "ctangle.w"
  323.  
  324. typedef struct{
  325. #line 211 "ctangle.ch"
  326. eight_bits HUGE*tok_start;
  327. #line 152 "ctangle.w"
  328. sixteen_bits text_link;
  329. }text;
  330. typedef text*text_pointer;
  331.  
  332. /*:16*//*27:*/
  333. #line 293 "ctangle.w"
  334.  
  335. typedef struct{
  336. #line 321 "ctangle.ch"
  337. eight_bits HUGE*end_field;
  338. eight_bits HUGE*byte_field;
  339. #line 297 "ctangle.w"
  340. name_pointer name_field;
  341. text_pointer repl_field;
  342. sixteen_bits section_field;
  343. }output_state;
  344. typedef output_state*stack_pointer;
  345.  
  346. /*:27*/
  347. #line 65 "ctangle.w"
  348.  
  349. /*17:*/
  350. #line 156 "ctangle.w"
  351.  
  352. #line 219 "ctangle.ch"
  353. text*text_info;
  354. text_pointer text_info_end;
  355. #line 159 "ctangle.w"
  356. text_pointer text_ptr;
  357. #line 229 "ctangle.ch"
  358. eight_bits HUGE*tok_mem;
  359. eight_bits HUGE*tok_mem_end;
  360. eight_bits HUGE*tok_ptr;
  361. #line 163 "ctangle.w"
  362.  
  363. /*:17*//*23:*/
  364. #line 224 "ctangle.w"
  365.  
  366. text_pointer last_unnamed;
  367.  
  368. /*:23*//*28:*/
  369. #line 309 "ctangle.w"
  370.  
  371. output_state cur_state;
  372.  
  373. #line 331 "ctangle.ch"
  374. output_state*stack;
  375. stack_pointer stack_ptr;
  376. stack_pointer stack_end;
  377. #line 315 "ctangle.w"
  378.  
  379. /*:28*//*32:*/
  380. #line 381 "ctangle.w"
  381.  
  382. int cur_val;
  383.  
  384. /*:32*//*36:*/
  385. #line 467 "ctangle.w"
  386.  
  387. eight_bits out_state;
  388. boolean protect;
  389.  
  390. /*:36*//*38:*/
  391. #line 496 "ctangle.w"
  392.  
  393. #line 399 "ctangle.ch"
  394. name_pointer*output_files;
  395. name_pointer*cur_out_file,*end_output_files,*an_output_file;
  396. char cur_section_name_char;
  397. char*output_file_name;
  398.  
  399. /*:38*//*45:*/
  400. #line 592 "ctangle.w"
  401.  
  402. boolean output_defs_seen= 0;
  403.  
  404. #line 482 "ctangle.ch"
  405. /*:45*//*51:*/
  406. #line 699 "ctangle.w"
  407.  
  408. #line 528 "ctangle.ch"
  409. char**translit;
  410.  
  411. /*:51*//*56:*/
  412. #line 775 "ctangle.w"
  413.  
  414. #line 548 "ctangle.ch"
  415. eight_bits*ccode;
  416.  
  417. /*:56*//*59:*/
  418. #line 831 "ctangle.w"
  419.  
  420. #line 832 "ctangle.w"
  421. boolean comment_continues= 0;
  422.  
  423. /*:59*//*61:*/
  424. #line 870 "ctangle.w"
  425.  
  426. name_pointer cur_section_name;
  427.  
  428. /*:61*//*75:*/
  429. #line 1180 "ctangle.w"
  430.  
  431. text_pointer cur_text;
  432. eight_bits next_control;
  433.  
  434. /*:75*//*82:*/
  435. #line 1327 "ctangle.w"
  436.  
  437. extern sixteen_bits section_count;
  438.  
  439. /*:82*//*97:*/
  440. #line 921 "ctangle.ch"
  441.  
  442. #ifdef _AMIGA
  443. const unsigned char*Version= "$VER: CTangle 3.1 [p9d] "__AMIGADATE__;
  444. #endif
  445.  
  446. /*:97*/
  447. #line 66 "ctangle.w"
  448.  
  449. /*41:*/
  450. #line 431 "ctangle.ch"
  451.  
  452. #line 432 "ctangle.ch"
  453. static void phase_two(void);
  454.  
  455. /*:41*//*46:*/
  456. #line 482 "ctangle.ch"
  457.  
  458. static void output_defs(void);
  459.  
  460. /*:46*//*48:*/
  461. #line 508 "ctangle.ch"
  462.  
  463. #line 509 "ctangle.ch"
  464. static void out_char(eight_bits);
  465.  
  466. /*:48*//*90:*/
  467. #line 800 "ctangle.ch"
  468.  
  469. static void phase_one(void);
  470.  
  471. /*:90*//*92:*/
  472. #line 816 "ctangle.ch"
  473.  
  474. #line 817 "ctangle.ch"
  475. static void skip_limbo(void);
  476.  
  477. /*:92*//*96:*/
  478. #line 904 "ctangle.ch"
  479.  
  480. static eight_bits get_next(void);
  481. static eight_bits skip_ahead(void);
  482. static int skip_comment(boolean);
  483. static void flush_buffer(void);
  484. static void get_output(void);
  485. static void pop_level(int);
  486. static void push_level(name_pointer);
  487. static void scan_repl(eight_bits);
  488. static void scan_section(void);
  489. static void store_two_bytes(sixteen_bits);
  490.  
  491. /*:96*/
  492. #line 67 "ctangle.w"
  493.  
  494.  
  495. #line 172 "ctangle.ch"
  496. /*:1*//*3:*/
  497. #line 88 "ctangle.w"
  498.  
  499. #line 187 "ctangle.ch"
  500. int main(int ac,char**av)
  501. #line 92 "ctangle.w"
  502. {
  503. argc= ac;argv= av;
  504. program= ctangle;
  505. #line 195 "ctangle.ch"
  506. common_init();
  507. /*18:*/
  508. #line 164 "ctangle.w"
  509.  
  510. #line 238 "ctangle.ch"
  511. alloc_object(section_text,longest_name+1,char);
  512. section_text_end= section_text+longest_name;
  513. alloc_object(text_info,max_texts,text);
  514. text_info_end= text_info+max_texts-1;
  515. #ifdef __TURBOC__
  516. tok_mem= allocsafe(max_toks,sizeof(*tok_mem));
  517. #else
  518. alloc_object(tok_mem,max_toks,eight_bits);
  519. #endif
  520. tok_mem_end= tok_mem+max_toks-1;
  521. text_info->tok_start= tok_ptr= tok_mem;
  522. alloc_object(stack,stack_size+1,output_state);
  523. stack_end= stack+stack_size;
  524.  
  525. #line 166 "ctangle.w"
  526. text_ptr= text_info+1;text_ptr->tok_start= tok_mem;
  527.  
  528.  
  529. /*:18*//*20:*/
  530. #line 174 "ctangle.w"
  531.  
  532. #line 258 "ctangle.ch"
  533. name_dir->equiv= (void HUGE*)text_info;
  534. #line 176 "ctangle.w"
  535.  
  536. /*:20*//*24:*/
  537. #line 227 "ctangle.w"
  538. last_unnamed= text_info;text_info->text_link= 0;
  539.  
  540. /*:24*//*39:*/
  541. #line 409 "ctangle.ch"
  542.  
  543. alloc_object(output_files,max_files,name_pointer);
  544. alloc_object(output_file_name,longest_name,char);
  545. cur_out_file= end_output_files= output_files+max_files;
  546. #line 508 "ctangle.w"
  547.  
  548. /*:39*//*52:*/
  549. #line 530 "ctangle.ch"
  550.  
  551. {
  552. int i;
  553. alloc_object(translit,128,char*);
  554. for(i= 0;i<128;i++)
  555. alloc_object(translit[i],translit_length,char);
  556. for(i= 0;i<128;i++)
  557. sprintf(translit[i],"X%02X",(unsigned)(128+i));
  558. }
  559. #line 707 "ctangle.w"
  560.  
  561. /*:52*//*57:*/
  562. #line 550 "ctangle.ch"
  563. {
  564. int c;
  565. alloc_object(ccode,256,eight_bits);
  566. #line 780 "ctangle.w"
  567. for(c= 0;c<256;c++)ccode[c]= ignore;
  568. ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
  569. = ccode['*']= new_section;
  570. ccode['@']= '@';ccode['=']= string;
  571. ccode['d']= ccode['D']= definition;
  572. ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
  573. ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
  574. ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= 
  575. ccode['q']= ccode['Q']= control_text;
  576. ccode['h']= ccode['H']= output_defs_code;
  577. ccode['l']= ccode['L']= translit_code;
  578. ccode['&']= join;
  579. ccode['<']= ccode['(']= section_name;
  580. ccode['\'']= ord;
  581. }
  582.  
  583. /*:57*//*71:*/
  584. #line 1104 "ctangle.w"
  585. section_text[0]= ' ';
  586.  
  587. /*:71*/
  588. #line 196 "ctangle.ch"
  589. ;
  590. #line 97 "ctangle.w"
  591. if(show_banner)printf(banner);
  592. phase_one();
  593. phase_two();
  594. return wrap_up();
  595. }
  596.  
  597. /*:3*//*21:*/
  598. #line 180 "ctangle.w"
  599.  
  600. #line 268 "ctangle.ch"
  601. int names_match(name_pointer p,char*first,int l,eight_bits dummy)
  602.  
  603.  
  604.  
  605.  
  606. #line 185 "ctangle.w"
  607. {
  608. if(length(p)!=l)return 0;
  609. return!strncmp(first,p->byte_start,l);
  610. }
  611.  
  612. /*:21*//*22:*/
  613. #line 195 "ctangle.w"
  614.  
  615. #line 281 "ctangle.ch"
  616. void init_node(name_pointer node)
  617. #line 199 "ctangle.w"
  618. {
  619. #line 288 "ctangle.ch"
  620. node->equiv= (void HUGE*)text_info;
  621. #line 201 "ctangle.w"
  622. }
  623. #line 296 "ctangle.ch"
  624. void init_p(name_pointer dummy1,eight_bits dummy2)
  625. {}
  626. #line 204 "ctangle.w"
  627.  
  628. /*:22*//*26:*/
  629. #line 257 "ctangle.w"
  630.  
  631. #line 306 "ctangle.ch"
  632. static void store_two_bytes(sixteen_bits x)
  633. #line 261 "ctangle.w"
  634. {
  635. #line 313 "ctangle.ch"
  636. if(tok_ptr+2>tok_mem_end)overflow(get_string(MSG_OVERFLOW_CT26));
  637. #line 263 "ctangle.w"
  638. *tok_ptr++= x>>8;
  639. *tok_ptr++= x&0377;
  640. }
  641.  
  642. /*:26*//*30:*/
  643. #line 333 "ctangle.w"
  644.  
  645. #line 344 "ctangle.ch"
  646. static void push_level(name_pointer p)
  647. {
  648. if(stack_ptr==stack_end)overflow(get_string(MSG_OVERFLOW_CT30));
  649. #line 339 "ctangle.w"
  650. *stack_ptr= cur_state;
  651. stack_ptr++;
  652. if(p!=NULL){
  653. cur_name= p;cur_repl= (text_pointer)p->equiv;
  654. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  655. cur_section= 0;
  656. }
  657. }
  658.  
  659. /*:30*//*31:*/
  660. #line 352 "ctangle.w"
  661.  
  662. #line 355 "ctangle.ch"
  663. static void pop_level(int flag)
  664. #line 356 "ctangle.w"
  665. {
  666. if(flag&&cur_repl->text_link<section_flag){
  667. cur_repl= cur_repl->text_link+text_info;
  668. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  669. return;
  670. }
  671. stack_ptr--;
  672. if(stack_ptr>stack)cur_state= *stack_ptr;
  673. }
  674.  
  675. /*:31*//*33:*/
  676. #line 388 "ctangle.w"
  677.  
  678. #line 363 "ctangle.ch"
  679. static void get_output(void)
  680. #line 391 "ctangle.w"
  681. {
  682. sixteen_bits a;
  683. restart:if(stack_ptr==stack)return;
  684. if(cur_byte==cur_end){
  685. cur_val= -((int)cur_section);
  686. pop_level(1);
  687. if(cur_val==0)goto restart;
  688. out_char(section_number);return;
  689. }
  690. a= *cur_byte++;
  691. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  692. C_putc(a);
  693. else if(a<0200)out_char(a);
  694. else{
  695. a= (a-0200)*0400+*cur_byte++;
  696. switch(a/024000){
  697. case 0:cur_val= a;out_char(identifier);break;
  698. case 1:if(a==output_defs_flag)output_defs();
  699. else/*34:*/
  700. #line 420 "ctangle.w"
  701.  
  702. {
  703. a-= 024000;
  704. #line 372 "ctangle.ch"
  705. if((a+name_dir)->equiv!=(void HUGE*)text_info)push_level(a+name_dir);
  706. else if(a!=0){
  707. printf(get_string(MSG_ERROR_CT34));
  708. #line 426 "ctangle.w"
  709. print_section_name(a+name_dir);err_print(">");
  710.  
  711. }
  712. goto restart;
  713. }
  714.  
  715. /*:34*/
  716. #line 409 "ctangle.w"
  717. ;
  718. break;
  719. default:cur_val= a-050000;if(cur_val>0)cur_section= cur_val;
  720. out_char(section_number);
  721. }
  722. }
  723. }
  724.  
  725. /*:33*//*37:*/
  726. #line 475 "ctangle.w"
  727.  
  728. #line 382 "ctangle.ch"
  729. static void flush_buffer(void)
  730. #line 478 "ctangle.w"
  731. {
  732. C_putc('\n');
  733. if(cur_line%100==0&&show_progress){
  734. printf(".");
  735. if(cur_line%500==0)printf("%d",cur_line);
  736. update_terminal;
  737. }
  738. cur_line++;
  739. }
  740.  
  741. /*:37*//*42:*/
  742. #line 434 "ctangle.ch"
  743.  
  744. static void phase_two(void){
  745. #line 532 "ctangle.w"
  746. web_file_open= 0;
  747. cur_line= 1;
  748. /*29:*/
  749. #line 322 "ctangle.w"
  750.  
  751. stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;
  752. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;
  753.  
  754. /*:29*/
  755. #line 534 "ctangle.w"
  756. ;
  757. /*44:*/
  758. #line 588 "ctangle.w"
  759.  
  760. if(!output_defs_seen)
  761. output_defs();
  762.  
  763. /*:44*/
  764. #line 535 "ctangle.w"
  765. ;
  766. if(text_info->text_link==0&&cur_out_file==end_output_files){
  767. #line 442 "ctangle.ch"
  768. printf(get_string(MSG_WARNING_CT42));mark_harmless;
  769. #line 538 "ctangle.w"
  770.  
  771. }
  772. else{
  773. if(cur_out_file==end_output_files){
  774. if(show_progress)
  775. #line 449 "ctangle.ch"
  776. printf(get_string(MSG_PROGRESS_CT42_1),C_file_name);
  777. #line 544 "ctangle.w"
  778. }
  779. else{
  780. if(show_progress){
  781. #line 456 "ctangle.ch"
  782. printf(get_string(MSG_PROGRESS_CT42_2));
  783. #line 548 "ctangle.w"
  784.  
  785. printf(" (%s)",C_file_name);
  786. update_terminal;
  787. }
  788. if(text_info->text_link==0)goto writeloop;
  789. }
  790. while(stack_ptr>stack)get_output();
  791. flush_buffer();
  792. writeloop:/*43:*/
  793. #line 565 "ctangle.w"
  794.  
  795. for(an_output_file= end_output_files;an_output_file>cur_out_file;){
  796. an_output_file--;
  797. sprint_section_name(output_file_name,*an_output_file);
  798. fclose(C_file);
  799. C_file= fopen(output_file_name,"w");
  800. #line 470 "ctangle.ch"
  801. if(C_file==0)fatal(get_string(MSG_FATAL_CO78),output_file_name);
  802. #line 572 "ctangle.w"
  803.  
  804. printf("\n(%s)",output_file_name);update_terminal;
  805. cur_line= 1;
  806. stack_ptr= stack+1;
  807. cur_name= (*an_output_file);
  808. cur_repl= (text_pointer)cur_name->equiv;
  809. cur_byte= cur_repl->tok_start;
  810. cur_end= (cur_repl+1)->tok_start;
  811. while(stack_ptr>stack)get_output();
  812. flush_buffer();
  813. }
  814.  
  815. /*:43*/
  816. #line 556 "ctangle.w"
  817. ;
  818. #line 463 "ctangle.ch"
  819. if(show_happiness)printf(get_string(MSG_PROGRESS_CT42_3));
  820. #line 558 "ctangle.w"
  821. }
  822. }
  823.  
  824. /*:42*//*47:*/
  825. #line 485 "ctangle.ch"
  826.  
  827. static void output_defs(void)
  828. #line 601 "ctangle.w"
  829. {
  830. sixteen_bits a;
  831. push_level(NULL);
  832. for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)
  833. if(cur_text->text_link==0){
  834. cur_byte= cur_text->tok_start;
  835. cur_end= (cur_text+1)->tok_start;
  836. C_printf("%s","#define ");
  837. out_state= normal;
  838. protect= 1;
  839. while(cur_byte<cur_end){
  840. a= *cur_byte++;
  841. if(cur_byte==cur_end&&a=='\n')break;
  842. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  843. C_putc(a);
  844.  
  845. else if(a<0200)out_char(a);
  846. else{
  847. a= (a-0200)*0400+*cur_byte++;
  848. if(a<024000){
  849. cur_val= a;out_char(identifier);
  850. }
  851. #line 493 "ctangle.ch"
  852. else if(a<050000){confusion(get_string(MSG_CONFUSION_CT47));}
  853. #line 624 "ctangle.w"
  854. else{
  855. cur_val= a-050000;cur_section= cur_val;out_char(section_number);
  856. }
  857.  
  858. }
  859. }
  860. protect= 0;
  861. flush_buffer();
  862. }
  863. pop_level(0);
  864. }
  865.  
  866. /*:47*//*49:*/
  867. #line 511 "ctangle.ch"
  868.  
  869. static void out_char(eight_bits cur_char)
  870. {
  871. char HUGE*j;
  872. char HUGE*k;
  873. #line 650 "ctangle.w"
  874. restart:
  875. switch(cur_char){
  876. case'\n':if(protect)C_putc(' ');
  877. if(protect||out_state==verbatim)C_putc('\\');
  878. flush_buffer();if(out_state!=verbatim)out_state= normal;break;
  879. /*53:*/
  880. #line 708 "ctangle.w"
  881.  
  882. case identifier:
  883. if(out_state==num_or_id)C_putc(' ');
  884. j= (cur_val+name_dir)->byte_start;
  885. k= (cur_val+name_dir+1)->byte_start;
  886. while(j<k){
  887. if((unsigned char)(*j)<0200)C_putc(*j);
  888.  
  889. else C_printf("%s",translit[(unsigned char)(*j)-0200]);
  890. j++;
  891. }
  892. out_state= num_or_id;break;
  893.  
  894. /*:53*/
  895. #line 655 "ctangle.w"
  896. ;
  897. /*54:*/
  898. #line 721 "ctangle.w"
  899.  
  900. case section_number:
  901. if(cur_val>0)C_printf("/*%d:*/",cur_val);
  902. else if(cur_val<0)C_printf("/*:%d*/",-cur_val);
  903. else if(protect){
  904. cur_byte+= 4;
  905. cur_char= '\n';
  906. goto restart;
  907. }else{
  908. sixteen_bits a;
  909. a= 0400**cur_byte++;
  910. a+= *cur_byte++;
  911. C_printf("\n#line %d \"",a);
  912.  
  913. cur_val= *cur_byte++;
  914. cur_val= 0400*(cur_val-0200)+*cur_byte++;
  915. for(j= (cur_val+name_dir)->byte_start,k= (cur_val+name_dir+1)->byte_start;
  916. j<k;j++)C_putc(*j);
  917. C_printf("%s","\"\n");
  918. }
  919. break;
  920.  
  921. /*:54*/
  922. #line 656 "ctangle.w"
  923. ;
  924. /*50:*/
  925. #line 670 "ctangle.w"
  926.  
  927. case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;
  928. case minus_minus:C_putc('-');C_putc('-');out_state= normal;break;
  929. case minus_gt:C_putc('-');C_putc('>');out_state= normal;break;
  930. case gt_gt:C_putc('>');C_putc('>');out_state= normal;break;
  931. case eq_eq:C_putc('=');C_putc('=');out_state= normal;break;
  932. case lt_lt:C_putc('<');C_putc('<');out_state= normal;break;
  933. case gt_eq:C_putc('>');C_putc('=');out_state= normal;break;
  934. case lt_eq:C_putc('<');C_putc('=');out_state= normal;break;
  935. case not_eq:C_putc('!');C_putc('=');out_state= normal;break;
  936. case and_and:C_putc('&');C_putc('&');out_state= normal;break;
  937. case or_or:C_putc('|');C_putc('|');out_state= normal;break;
  938. case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal;
  939. break;
  940. case colon_colon:C_putc(':');C_putc(':');out_state= normal;break;
  941. case period_ast:C_putc('.');C_putc('*');out_state= normal;break;
  942. case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal;
  943. break;
  944.  
  945. /*:50*/
  946. #line 657 "ctangle.w"
  947. ;
  948. case'=':C_putc('=');C_putc(' ');out_state= normal;break;
  949. case join:out_state= unbreakable;break;
  950. case constant:if(out_state==verbatim){
  951. out_state= num_or_id;break;
  952. }
  953. if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break;
  954. case string:if(out_state==verbatim)out_state= normal;
  955. else out_state= verbatim;break;
  956. default:C_putc(cur_char);out_state= normal;break;
  957. }
  958. }
  959.  
  960. /*:49*//*58:*/
  961. #line 799 "ctangle.w"
  962.  
  963. #line 560 "ctangle.ch"
  964. static eight_bits skip_ahead(void)
  965. #line 802 "ctangle.w"
  966. {
  967. eight_bits c;
  968. while(1){
  969. if(loc>limit&&(get_line()==0))return(new_section);
  970. *(limit+1)= '@';
  971. while(*loc!='@')loc++;
  972. if(loc<=limit){
  973. loc++;c= ccode[(eight_bits)*loc];loc++;
  974. if(c!=ignore||*(loc-1)=='>')return(c);
  975. }
  976. }
  977. }
  978.  
  979. /*:58*//*60:*/
  980. #line 834 "ctangle.w"
  981.  
  982. #line 574 "ctangle.ch"
  983. static int skip_comment(boolean is_long_comment)
  984. #line 837 "ctangle.w"
  985. {
  986. char c;
  987. while(1){
  988. if(loc>limit){
  989. if(is_long_comment){
  990. if(get_line())return(comment_continues= 1);
  991. else{
  992. #line 581 "ctangle.ch"
  993. err_print(get_string(MSG_ERROR_CT60_1));
  994. #line 845 "ctangle.w"
  995.  
  996. return(comment_continues= 0);
  997. }
  998. }
  999. else return(comment_continues= 0);
  1000. }
  1001. c= *(loc++);
  1002. if(is_long_comment&&c=='*'&&*loc=='/'){
  1003. loc++;return(comment_continues= 0);
  1004. }
  1005. if(c=='@'){
  1006. if(ccode[(eight_bits)*loc]==new_section){
  1007. #line 588 "ctangle.ch"
  1008. err_print(get_string(MSG_ERROR_CT60_2));loc--;
  1009. #line 858 "ctangle.w"
  1010.  
  1011. return(comment_continues= 0);
  1012. }
  1013. else loc++;
  1014. }
  1015. }
  1016. }
  1017.  
  1018. /*:60*//*63:*/
  1019. #line 884 "ctangle.w"
  1020.  
  1021. #line 596 "ctangle.ch"
  1022. static eight_bits get_next(void)
  1023. #line 887 "ctangle.w"
  1024. {
  1025. static int preprocessing= 0;
  1026. eight_bits c;
  1027. while(1){
  1028. if(loc>limit){
  1029. if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
  1030. if(get_line()==0)return(new_section);
  1031. else if(print_where){
  1032. print_where= 0;
  1033. /*77:*/
  1034. #line 1207 "ctangle.w"
  1035.  
  1036. store_two_bytes(0150000);
  1037. if(changing)id_first= change_file_name;
  1038. else id_first= cur_file_name;
  1039. id_loc= id_first+strlen(id_first);
  1040. if(changing)store_two_bytes((sixteen_bits)change_line);
  1041. else store_two_bytes((sixteen_bits)cur_line);
  1042. #line 724 "ctangle.ch"
  1043. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1044. #line 1215 "ctangle.w"
  1045. app_repl(a%0400);}
  1046.  
  1047. /*:77*/
  1048. #line 896 "ctangle.w"
  1049. ;
  1050. }
  1051. else return('\n');
  1052. }
  1053. c= *loc;
  1054. if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
  1055. skip_comment(comment_continues||*(loc+1)=='*');
  1056.  
  1057. if(comment_continues)return('\n');
  1058. else continue;
  1059. }
  1060. loc++;
  1061. if(xisdigit(c)||c=='\\'||c=='.')/*66:*/
  1062. #line 962 "ctangle.w"
  1063. {
  1064. id_first= loc-1;
  1065. if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
  1066. if(*id_first=='\\')while(xisdigit(*loc))loc++;
  1067. else{
  1068. if(*id_first=='0'){
  1069. if(*loc=='x'||*loc=='X'){
  1070. loc++;while(xisxdigit(*loc))loc++;goto found;
  1071. }
  1072. }
  1073. while(xisdigit(*loc))loc++;
  1074. if(*loc=='.'){
  1075. loc++;
  1076. while(xisdigit(*loc))loc++;
  1077. }
  1078. if(*loc=='e'||*loc=='E'){
  1079. if(*++loc=='+'||*loc=='-')loc++;
  1080. while(xisdigit(*loc))loc++;
  1081. }
  1082. }
  1083. found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
  1084. ||*loc=='f'||*loc=='F')loc++;
  1085. id_loc= loc;
  1086. return(constant);
  1087. }
  1088.  
  1089. /*:66*/
  1090. #line 908 "ctangle.w"
  1091.  
  1092. else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
  1093. /*67:*/
  1094. #line 993 "ctangle.w"
  1095. {
  1096. char delim= c;
  1097. id_first= section_text+1;
  1098. id_loc= section_text;*++id_loc= delim;
  1099. if(delim=='L'){
  1100. delim= *loc++;*++id_loc= delim;
  1101. }
  1102. while(1){
  1103. if(loc>=limit){
  1104. if(*(limit-1)!='\\'){
  1105. #line 603 "ctangle.ch"
  1106. err_print(get_string(MSG_ERROR_CT67_1));loc= limit;break;
  1107. #line 1004 "ctangle.w"
  1108.  
  1109. }
  1110. if(get_line()==0){
  1111. #line 610 "ctangle.ch"
  1112. err_print(get_string(MSG_ERROR_CT67_2));loc= buffer;break;
  1113. #line 1008 "ctangle.w"
  1114.  
  1115. }
  1116. else if(++id_loc<=section_text_end)*id_loc= '\n';
  1117.  
  1118. }
  1119. if((c= *loc++)==delim){
  1120. if(++id_loc<=section_text_end)*id_loc= c;
  1121. break;
  1122. }
  1123. if(c=='\\'){
  1124. if(loc>=limit)continue;
  1125. if(++id_loc<=section_text_end)*id_loc= '\\';
  1126. c= *loc++;
  1127. }
  1128. if(++id_loc<=section_text_end)*id_loc= c;
  1129. }
  1130. if(id_loc>=section_text_end){
  1131. #line 617 "ctangle.ch"
  1132. printf(get_string(MSG_ERROR_CT67_3));
  1133. #line 1026 "ctangle.w"
  1134.  
  1135. term_write(section_text+1,25);
  1136. err_print("...");
  1137. }
  1138. id_loc++;
  1139. return(string);
  1140. }
  1141.  
  1142. /*:67*/
  1143. #line 910 "ctangle.w"
  1144.  
  1145. else if(isalpha(c)||isxalpha(c)||ishigh(c))
  1146. /*65:*/
  1147. #line 956 "ctangle.w"
  1148. {
  1149. id_first= --loc;
  1150. while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
  1151. id_loc= loc;return(identifier);
  1152. }
  1153.  
  1154. /*:65*/
  1155. #line 912 "ctangle.w"
  1156.  
  1157. else if(c=='@')/*68:*/
  1158. #line 1037 "ctangle.w"
  1159. {
  1160. c= ccode[(eight_bits)*loc++];
  1161. switch(c){
  1162. case ignore:continue;
  1163. case output_defs_code:output_defs_seen= 1;return(c);
  1164. #line 624 "ctangle.ch"
  1165. case translit_code:err_print(get_string(MSG_ERROR_CT68_1));continue;
  1166. #line 1043 "ctangle.w"
  1167.  
  1168. case control_text:while((c= skip_ahead())=='@');
  1169.  
  1170. if(*(loc-1)!='>')
  1171. #line 631 "ctangle.ch"
  1172. err_print(get_string(MSG_ERROR_CT68_2));
  1173. #line 1048 "ctangle.w"
  1174.  
  1175. continue;
  1176. case section_name:
  1177. cur_section_name_char= *(loc-1);
  1178. /*70:*/
  1179. #line 1086 "ctangle.w"
  1180. {
  1181. char*k;
  1182. /*72:*/
  1183. #line 1106 "ctangle.w"
  1184.  
  1185. k= section_text;
  1186. while(1){
  1187. if(loc>limit&&get_line()==0){
  1188. #line 652 "ctangle.ch"
  1189. err_print(get_string(MSG_ERROR_CT72_1));
  1190. #line 1111 "ctangle.w"
  1191.  
  1192. loc= buffer+1;break;
  1193. }
  1194. c= *loc;
  1195. /*73:*/
  1196. #line 1130 "ctangle.w"
  1197.  
  1198. if(c=='@'){
  1199. c= *(loc+1);
  1200. if(c=='>'){
  1201. loc+= 2;break;
  1202. }
  1203. if(ccode[(eight_bits)c]==new_section){
  1204. #line 666 "ctangle.ch"
  1205. err_print(get_string(MSG_ERROR_CT73_1));break;
  1206. #line 1138 "ctangle.w"
  1207.  
  1208. }
  1209. if(ccode[(eight_bits)c]==section_name){
  1210. #line 673 "ctangle.ch"
  1211. err_print(get_string(MSG_ERROR_CT73_2));break;
  1212. #line 1142 "ctangle.w"
  1213.  
  1214. }
  1215. *(++k)= '@';loc++;
  1216. }
  1217.  
  1218. /*:73*/
  1219. #line 1115 "ctangle.w"
  1220. ;
  1221. loc++;if(k<section_text_end)k++;
  1222. if(xisspace(c)){
  1223. c= ' ';if(*(k-1)==' ')k--;
  1224. }
  1225. *k= c;
  1226. }
  1227. if(k>=section_text_end){
  1228. #line 659 "ctangle.ch"
  1229. printf(get_string(MSG_ERROR_CT72_2));
  1230. #line 1124 "ctangle.w"
  1231.  
  1232. term_write(section_text+1,25);
  1233. printf("...");mark_harmless;
  1234. }
  1235. if(*k==' '&&k>section_text)k--;
  1236.  
  1237. /*:72*/
  1238. #line 1088 "ctangle.w"
  1239. ;
  1240. if(k-section_text>3&&strncmp(k-2,"...",3)==0)
  1241. cur_section_name= section_lookup(section_text+1,k-3,1);
  1242. else cur_section_name= section_lookup(section_text+1,k,0);
  1243. if(cur_section_name_char=='(')
  1244. /*40:*/
  1245. #line 510 "ctangle.w"
  1246.  
  1247. {
  1248. if(cur_out_file>output_files){
  1249. for(an_output_file= cur_out_file;
  1250. an_output_file<end_output_files;an_output_file++)
  1251. if(*an_output_file==cur_section_name)break;
  1252. if(an_output_file==end_output_files)
  1253. *--cur_out_file= cur_section_name;
  1254. }else{
  1255. #line 419 "ctangle.ch"
  1256. overflow(get_string(MSG_OVERFLOW_CT40));
  1257. #line 520 "ctangle.w"
  1258. }
  1259. }
  1260.  
  1261. /*:40*/
  1262. #line 1094 "ctangle.w"
  1263. ;
  1264. return(section_name);
  1265. }
  1266.  
  1267. /*:70*/
  1268. #line 1052 "ctangle.w"
  1269. ;
  1270. case string:/*74:*/
  1271. #line 1152 "ctangle.w"
  1272. {
  1273. id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
  1274. while(*loc!='@'||*(loc+1)!='>')loc++;
  1275. #line 680 "ctangle.ch"
  1276. if(loc>=limit)err_print(get_string(MSG_ERROR_CT74));
  1277. #line 1156 "ctangle.w"
  1278.  
  1279. id_loc= loc;loc+= 2;
  1280. return(string);
  1281. }
  1282.  
  1283. /*:74*/
  1284. #line 1053 "ctangle.w"
  1285. ;
  1286. case ord:/*69:*/
  1287. #line 1065 "ctangle.w"
  1288.  
  1289. id_first= loc;
  1290. if(*loc=='\\'){
  1291. if(*++loc=='\'')loc++;
  1292. }
  1293. while(*loc!='\''){
  1294. if(*loc=='@'){
  1295. if(*(loc+1)!='@')
  1296. #line 638 "ctangle.ch"
  1297. err_print(get_string(MSG_ERROR_CT69));
  1298. #line 1074 "ctangle.w"
  1299.  
  1300. else loc++;
  1301. }
  1302. loc++;
  1303. if(loc>limit){
  1304. #line 645 "ctangle.ch"
  1305. err_print(get_string(MSG_ERROR_CT67_1));loc= limit-1;break;
  1306. #line 1080 "ctangle.w"
  1307.  
  1308. }
  1309. }
  1310. loc++;
  1311. return(ord);
  1312.  
  1313. /*:69*/
  1314. #line 1054 "ctangle.w"
  1315. ;
  1316. default:return(c);
  1317. }
  1318. }
  1319.  
  1320. /*:68*/
  1321. #line 913 "ctangle.w"
  1322.  
  1323. else if(xisspace(c)){
  1324. if(!preprocessing||loc>limit)continue;
  1325.  
  1326. else return(' ');
  1327. }
  1328. else if(c=='#'&&loc==buffer+1)preprocessing= 1;
  1329. mistake:/*64:*/
  1330. #line 934 "ctangle.w"
  1331.  
  1332. switch(c){
  1333. case'+':if(*loc=='+')compress(plus_plus);break;
  1334. case'-':if(*loc=='-'){compress(minus_minus);}
  1335. else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
  1336. else compress(minus_gt);break;
  1337. case'.':if(*loc=='*'){compress(period_ast);}
  1338. else if(*loc=='.'&&*(loc+1)=='.'){
  1339. loc++;compress(dot_dot_dot);
  1340. }
  1341. break;
  1342. case':':if(*loc==':')compress(colon_colon);break;
  1343. case'=':if(*loc=='=')compress(eq_eq);break;
  1344. case'>':if(*loc=='='){compress(gt_eq);}
  1345. else if(*loc=='>')compress(gt_gt);break;
  1346. case'<':if(*loc=='='){compress(lt_eq);}
  1347. else if(*loc=='<')compress(lt_lt);break;
  1348. case'&':if(*loc=='&')compress(and_and);break;
  1349. case'|':if(*loc=='|')compress(or_or);break;
  1350. case'!':if(*loc=='=')compress(not_eq);break;
  1351. }
  1352.  
  1353. /*:64*/
  1354. #line 920 "ctangle.w"
  1355.  
  1356. return(c);
  1357. }
  1358. }
  1359.  
  1360. /*:63*//*76:*/
  1361. #line 1184 "ctangle.w"
  1362.  
  1363. #line 699 "ctangle.ch"
  1364. static void scan_repl(eight_bits t)
  1365. #line 1188 "ctangle.w"
  1366. {
  1367. sixteen_bits a;
  1368. if(t==section_name){/*77:*/
  1369. #line 1207 "ctangle.w"
  1370.  
  1371. store_two_bytes(0150000);
  1372. if(changing)id_first= change_file_name;
  1373. else id_first= cur_file_name;
  1374. id_loc= id_first+strlen(id_first);
  1375. if(changing)store_two_bytes((sixteen_bits)change_line);
  1376. else store_two_bytes((sixteen_bits)cur_line);
  1377. #line 724 "ctangle.ch"
  1378. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1379. #line 1215 "ctangle.w"
  1380. app_repl(a%0400);}
  1381.  
  1382. /*:77*/
  1383. #line 1190 "ctangle.w"
  1384. ;}
  1385. while(1)switch(a= get_next()){
  1386. /*78:*/
  1387. #line 1217 "ctangle.w"
  1388.  
  1389. #line 731 "ctangle.ch"
  1390. case identifier:a= id_lookup(id_first,id_loc,' ')-name_dir;
  1391. #line 1219 "ctangle.w"
  1392. app_repl((a/0400)+0200);
  1393. app_repl(a%0400);break;
  1394. case section_name:if(t!=section_name)goto done;
  1395. else{
  1396. /*79:*/
  1397. #line 1245 "ctangle.w"
  1398. {
  1399. char*try_loc= loc;
  1400. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1401. if(*try_loc=='+'&&try_loc<limit)try_loc++;
  1402. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1403. #line 745 "ctangle.ch"
  1404. if(*try_loc=='=')err_print(get_string(MSG_ERROR_CT79));
  1405. #line 1251 "ctangle.w"
  1406.  
  1407.  
  1408.  
  1409. }
  1410.  
  1411. /*:79*/
  1412. #line 1223 "ctangle.w"
  1413. ;
  1414. a= cur_section_name-name_dir;
  1415. app_repl((a/0400)+0250);
  1416. app_repl(a%0400);
  1417. /*77:*/
  1418. #line 1207 "ctangle.w"
  1419.  
  1420. store_two_bytes(0150000);
  1421. if(changing)id_first= change_file_name;
  1422. else id_first= cur_file_name;
  1423. id_loc= id_first+strlen(id_first);
  1424. if(changing)store_two_bytes((sixteen_bits)change_line);
  1425. else store_two_bytes((sixteen_bits)cur_line);
  1426. #line 724 "ctangle.ch"
  1427. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1428. #line 1215 "ctangle.w"
  1429. app_repl(a%0400);}
  1430.  
  1431. /*:77*/
  1432. #line 1227 "ctangle.w"
  1433. ;break;
  1434. }
  1435. case output_defs_code:
  1436. a= output_defs_flag;
  1437. app_repl((a/0400)+0200);
  1438. app_repl(a%0400);
  1439. /*77:*/
  1440. #line 1207 "ctangle.w"
  1441.  
  1442. store_two_bytes(0150000);
  1443. if(changing)id_first= change_file_name;
  1444. else id_first= cur_file_name;
  1445. id_loc= id_first+strlen(id_first);
  1446. if(changing)store_two_bytes((sixteen_bits)change_line);
  1447. else store_two_bytes((sixteen_bits)cur_line);
  1448. #line 724 "ctangle.ch"
  1449. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1450. #line 1215 "ctangle.w"
  1451. app_repl(a%0400);}
  1452.  
  1453. /*:77*/
  1454. #line 1233 "ctangle.w"
  1455. ;break;
  1456. case constant:case string:
  1457. /*80:*/
  1458. #line 1256 "ctangle.w"
  1459.  
  1460. app_repl(a);
  1461. while(id_first<id_loc){
  1462. if(*id_first=='@'){
  1463. if(*(id_first+1)=='@')id_first++;
  1464. #line 752 "ctangle.ch"
  1465. else err_print(get_string(MSG_ERROR_CT80));
  1466. #line 1262 "ctangle.w"
  1467.  
  1468. }
  1469. app_repl(*id_first++);
  1470. }
  1471. app_repl(a);break;
  1472.  
  1473. /*:80*/
  1474. #line 1235 "ctangle.w"
  1475. ;
  1476. case ord:
  1477. /*81:*/
  1478. #line 1272 "ctangle.w"
  1479. {
  1480. int c= (eight_bits)*id_first;
  1481. if(c=='\\'){
  1482. c= *++id_first;
  1483. if(c>='0'&&c<='7'){
  1484. c-= '0';
  1485. if(*(id_first+1)>='0'&&*(id_first+1)<='7'){
  1486. c= 8*c+*(++id_first)-'0';
  1487. if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32)
  1488. c= 8*c+*(++id_first)-'0';
  1489. }
  1490. }
  1491. else switch(c){
  1492. case't':c= '\t';break;
  1493. case'n':c= '\n';break;
  1494. case'b':c= '\b';break;
  1495. case'f':c= '\f';break;
  1496. case'v':c= '\v';break;
  1497. case'r':c= '\r';break;
  1498. case'a':c= '\7';break;
  1499. case'?':c= '?';break;
  1500. case'x':
  1501. if(xisdigit(*(id_first+1)))c= *(++id_first)-'0';
  1502. else if(xisxdigit(*(id_first+1))){
  1503. ++id_first;
  1504. c= toupper(*id_first)-'A'+10;
  1505. }
  1506. if(xisdigit(*(id_first+1)))c= 16*c+*(++id_first)-'0';
  1507. else if(xisxdigit(*(id_first+1))){
  1508. ++id_first;
  1509. c= 16*c+toupper(*id_first)-'A'+10;
  1510. }
  1511. break;
  1512. case'\\':c= '\\';break;
  1513. case'\'':c= '\'';break;
  1514. case'\"':c= '\"';break;
  1515. #line 759 "ctangle.ch"
  1516. default:err_print(get_string(MSG_ERROR_CT81));
  1517. #line 1309 "ctangle.w"
  1518.  
  1519. }
  1520. }
  1521.  
  1522. app_repl(constant);
  1523. if(c>=100)app_repl('0'+c/100);
  1524. if(c>=10)app_repl('0'+(c/10)%10);
  1525. app_repl('0'+c%10);
  1526. app_repl(constant);
  1527. }
  1528. break;
  1529.  
  1530. /*:81*/
  1531. #line 1237 "ctangle.w"
  1532. ;
  1533. case definition:case format_code:case begin_C:if(t!=section_name)goto done;
  1534. else{
  1535. #line 738 "ctangle.ch"
  1536. err_print(get_string(MSG_ERROR_CT78));continue;
  1537. #line 1241 "ctangle.w"
  1538.  
  1539. }
  1540. case new_section:goto done;
  1541.  
  1542. /*:78*/
  1543. #line 1195 "ctangle.w"
  1544.  
  1545. #line 706 "ctangle.ch"
  1546. case')':
  1547.  
  1548.  
  1549. app_repl(a);if(t==macro)app_repl(' ');break;
  1550. default:app_repl(a);
  1551. #line 1197 "ctangle.w"
  1552. }
  1553. done:next_control= (eight_bits)a;
  1554. #line 717 "ctangle.ch"
  1555. if(text_ptr>text_info_end)overflow(get_string(MSG_OVERFLOW_CT76));
  1556. #line 1200 "ctangle.w"
  1557. cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr;
  1558. }
  1559.  
  1560. /*:76*//*83:*/
  1561. #line 1334 "ctangle.w"
  1562.  
  1563. #line 767 "ctangle.ch"
  1564. static void scan_section(void)
  1565. #line 1337 "ctangle.w"
  1566. {
  1567. name_pointer p;
  1568. text_pointer q;
  1569. sixteen_bits a;
  1570. section_count++;
  1571. if(*(loc-1)=='*'&&show_progress){
  1572. printf("*%d",section_count);update_terminal;
  1573. }
  1574. next_control= 0;
  1575. while(1){
  1576. /*84:*/
  1577. #line 1372 "ctangle.w"
  1578.  
  1579. while(next_control<definition)
  1580.  
  1581. if((next_control= skip_ahead())==section_name){
  1582. loc-= 2;next_control= get_next();
  1583. }
  1584.  
  1585. /*:84*/
  1586. #line 1348 "ctangle.w"
  1587. ;
  1588. if(next_control==definition){
  1589. /*85:*/
  1590. #line 1379 "ctangle.w"
  1591. {
  1592. while((next_control= get_next())=='\n');
  1593. if(next_control!=identifier){
  1594. #line 774 "ctangle.ch"
  1595. err_print(get_string(MSG_ERROR_CT85));
  1596. #line 1383 "ctangle.w"
  1597.  
  1598. continue;
  1599. }
  1600. #line 781 "ctangle.ch"
  1601. app_repl(((a= id_lookup(id_first,id_loc,' ')-name_dir)/0400)+0200);
  1602. #line 1387 "ctangle.w"
  1603.  
  1604. app_repl(a%0400);
  1605. if(*loc!='('){
  1606. app_repl(string);app_repl(' ');app_repl(string);
  1607. }
  1608. print_where= 0;scan_repl(macro);
  1609. cur_text->text_link= 0;
  1610. }
  1611.  
  1612. /*:85*/
  1613. #line 1350 "ctangle.w"
  1614.  
  1615. continue;
  1616. }
  1617. if(next_control==begin_C){
  1618. p= name_dir;break;
  1619. }
  1620. if(next_control==section_name){
  1621. p= cur_section_name;
  1622. /*86:*/
  1623. #line 1404 "ctangle.w"
  1624.  
  1625. while((next_control= get_next())=='+');
  1626. if(next_control!='='&&next_control!=eq_eq)
  1627. continue;
  1628.  
  1629. /*:86*/
  1630. #line 1358 "ctangle.w"
  1631. ;
  1632. break;
  1633. }
  1634. return;
  1635. }
  1636. /*87:*/
  1637. #line 1409 "ctangle.w"
  1638.  
  1639. /*88:*/
  1640. #line 1414 "ctangle.w"
  1641.  
  1642. store_two_bytes((sixteen_bits)(0150000+section_count));
  1643.  
  1644.  
  1645. /*:88*/
  1646. #line 1410 "ctangle.w"
  1647. ;
  1648. scan_repl(section_name);
  1649. /*89:*/
  1650. #line 1418 "ctangle.w"
  1651.  
  1652. if(p==name_dir||p==0){
  1653. (last_unnamed)->text_link= cur_text-text_info;last_unnamed= cur_text;
  1654. }
  1655. #line 788 "ctangle.ch"
  1656. else if(p->equiv==(void HUGE*)text_info)p->equiv= (void HUGE*)cur_text;
  1657. #line 1423 "ctangle.w"
  1658.  
  1659. else{
  1660. q= (text_pointer)p->equiv;
  1661. while(q->text_link<section_flag)
  1662. q= q->text_link+text_info;
  1663. q->text_link= cur_text-text_info;
  1664. }
  1665. cur_text->text_link= section_flag;
  1666.  
  1667.  
  1668. #line 800 "ctangle.ch"
  1669. /*:89*/
  1670. #line 1412 "ctangle.w"
  1671. ;
  1672.  
  1673. /*:87*/
  1674. #line 1363 "ctangle.w"
  1675. ;
  1676. }
  1677.  
  1678. /*:83*//*91:*/
  1679. #line 803 "ctangle.ch"
  1680.  
  1681. static void phase_one(void){
  1682. #line 1439 "ctangle.w"
  1683. phase= 1;
  1684. section_count= 0;
  1685. reset_input();
  1686. skip_limbo();
  1687. while(!input_has_ended)scan_section();
  1688. check_complete();
  1689. phase= 2;
  1690. }
  1691.  
  1692. /*:91*//*93:*/
  1693. #line 819 "ctangle.ch"
  1694.  
  1695. static void skip_limbo(void)
  1696. #line 1457 "ctangle.w"
  1697. {
  1698. char c;
  1699. while(1){
  1700. if(loc>limit&&get_line()==0)return;
  1701. *(limit+1)= '@';
  1702. while(*loc!='@')loc++;
  1703. if(loc++<=limit){
  1704. c= *loc++;
  1705. if(ccode[(eight_bits)c]==new_section)break;
  1706. switch(ccode[(eight_bits)c]){
  1707. case translit_code:/*94:*/
  1708. #line 1483 "ctangle.w"
  1709.  
  1710. while(xisspace(*loc)&&loc<limit)loc++;
  1711. loc+= 3;
  1712. if(loc>limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2))
  1713. ||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1)))
  1714. #line 841 "ctangle.ch"
  1715. err_print(get_string(MSG_ERROR_CT94_1));
  1716. #line 1489 "ctangle.w"
  1717.  
  1718. else{
  1719. unsigned i;
  1720. char*beg;
  1721. sscanf(loc-3,"%x",&i);
  1722. while(xisspace(*loc)&&loc<limit)loc++;
  1723. beg= loc;
  1724. while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||*loc=='_'))loc++;
  1725. if(loc-beg>=translit_length)
  1726. #line 848 "ctangle.ch"
  1727. err_print(get_string(MSG_ERROR_CT94_2));
  1728. #line 1499 "ctangle.w"
  1729.  
  1730. else{
  1731. #line 855 "ctangle.ch"
  1732. strncpy(translit[i-0200],beg,(size_t)(loc-beg));
  1733. #line 1502 "ctangle.w"
  1734. translit[i-0200][loc-beg]= '\0';
  1735. }
  1736. }
  1737.  
  1738. #line 877 "ctangle.ch"
  1739. /*:94*/
  1740. #line 1467 "ctangle.w"
  1741. ;break;
  1742. case format_code:case'@':break;
  1743. case control_text:if(c=='q'||c=='Q'){
  1744. while((c= skip_ahead())=='@');
  1745. if(*(loc-1)!='>')
  1746. #line 827 "ctangle.ch"
  1747. err_print(get_string(MSG_ERROR_CT68_2));
  1748. #line 1473 "ctangle.w"
  1749.  
  1750. break;
  1751. }
  1752. #line 834 "ctangle.ch"
  1753. default:err_print(get_string(MSG_ERROR_CT93));
  1754. #line 1477 "ctangle.w"
  1755.  
  1756. }
  1757. }
  1758. }
  1759. }
  1760.  
  1761. /*:93*//*95:*/
  1762. #line 882 "ctangle.ch"
  1763.  
  1764. void print_stats(void){
  1765. printf(get_string(MSG_STATS_CT95_1));
  1766. printf(get_string(MSG_STATS_CT95_2),
  1767. (long)(name_ptr-name_dir),(long)max_names);
  1768. printf(get_string(MSG_STATS_CT95_3),
  1769. (long)(text_ptr-text_info),(long)max_texts);
  1770. printf(get_string(MSG_STATS_CT95_4),
  1771. (long)(byte_ptr-byte_mem),(long)max_bytes);
  1772. printf(get_string(MSG_STATS_CT95_5),
  1773. (long)(tok_ptr-tok_mem),(long)max_toks);
  1774. }
  1775. #line 1522 "ctangle.w"
  1776.  
  1777. #line 900 "ctangle.ch"
  1778. /*:95*/
  1779.